package com.web.currencypair.controller;

import com.web.common.BaseResult;
import com.web.common.enums.BaseStatus;
import com.web.currencypair.entity.CurrencyPair;
import com.web.currencypair.service.CurrencyPairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wenzhuo
 * @create 2024-01-10 2024/1/10
 */

@RestController
@CrossOrigin
@RequestMapping("/currencyPair")
public class CurrencyPairController {

    @Autowired
    private CurrencyPairService currencyPairService;

    @RequestMapping(value = "/currencyPairList")
    public BaseResult<List<CurrencyPair>> getCurrencyPairList(@RequestParam("currencyFrom") String currencyFrom, @RequestParam("currencyTo") String currencyTo){

        List<CurrencyPair> currencyPairList = currencyPairService.getCurrencyPairList(currencyFrom, currencyTo);
        return new BaseResult<>(BaseStatus.SUCCESS.getCode(),currencyPairList);
    }


    @RequestMapping(value = "/checkCurrencyPair")
    public BaseResult<CurrencyPair> checkCurrencyPair(@RequestParam("currencyFrom") String currencyFrom, @RequestParam("currencyTo") String currencyTo){

         CurrencyPair currencyPair = currencyPairService.checkCurrencyPair(currencyFrom, currencyTo);
         if(currencyPair == null){
             return new BaseResult<>(BaseStatus.INVALID_CURRENCY_PAIR.getCode(),BaseStatus.INVALID_CURRENCY_PAIR.getDesc());
         }

        return new BaseResult<>(BaseStatus.SUCCESS.getCode(),currencyPair);
    }


}
